$(document).ready(function () {

    $('.mainusers').html('');
    $('title').html("Είσοδος");


    $("#form-signin").submit(function (e) {

        var name = $('#user').val();
        var name2 = $('#pass').val();

        if (name2.length < 8) {
            alert(' Password length failed !');
            e.preventDefault();
            return ;
        }

        $("#msgbox").removeClass().addClass('messagebox').text(' authenticating ').fadeIn(1000);


        $.postJSON('App/Api/Auth.php', { user: name, pass: name2, call_service: 'ss' }, function (data, status, xhr) {


                if (status == 'success') {
                    if (data.Auth === 'FALSE') {
                        $("#msgbox").fadeTo(200, 0.1, function () {
                            $(this).html(data.Result).addClass('messageboxerror').fadeTo(900, .9,
                                function () {
                                    $(this).hide();
                                });
                        });
                    }
                    if (data.Auth === 'TRUE') {
                        $("#msgbox").fadeTo(200, 0.1, function () {
                            $(this).html(' entering ... ').addClass('messageboxok').fadeTo(900, 1,
                                function () {
                                    document.location = data.URL;
                                });
                        });
                    }
                }
                else {

                    $("#msgbox").fadeTo(200, 0.1, function () {
                        $(this).html('Failed to Connect!').addClass('messageboxerror').fadeTo(900, .9,
                            function () {
                                $(this).hide();
                            });
                    });
                }
            }
        );

        return false;
    });
});
